package com.example.service.impl;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.constant.Constant;
import com.example.dao.UserDao;
import com.example.entity.UserPO;
import com.example.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserDao, UserPO> implements UserService {
    //
    @Resource
    private UserDao userDao;

    @Override
    public UserPO get1ById(Integer id) {
        return userDao.get1ById(id);
    }

    @Override
    public UserPO get2ById(Integer id) {
        return userDao.get2ById(id);
    }

    @Override
    // 分布式事务注解
    @DSTransactional
    public String addUser() {
        UserPO user = new UserPO();
        user.setName("诸葛亮");
        user.setAge(53);
        user.setBirthYear("181年");
        user.setCamp("蜀");
        userDao.insert(user);

        UserPO user01 = new UserPO();
        user01.setName("项羽");
        user01.setAge(31);
        user01.setBirthYear("公元前232年");
        user01.setCamp("楚");
        userDao.insert01DB(user01);
        int zero= 0;
        log.info("{}",6/zero);
        UserPO user02 = new UserPO();
        user02.setName("商鞅");
        user02.setAge(53);
        user02.setBirthYear("公元前390年");
        user02.setCamp("秦");
        userDao.insert02DB(user02);

        return Constant.SUCCESS;
    }
}
